const benchmark = require('benchmark')
const {createIdentifierByString} = require("./Identifier");
const {ControlParameters} = require("./ControlParameters");
const {Encoder, MaxPacketSize} = require("../encoding/Encoder")
const {createBlockByBuffer} = require("../encoding/Block")

let parameters = new ControlParameters()
let prefix = createIdentifierByString("/pku/sz")
parameters.ControlParameterPrefix.setPrefix(prefix)
parameters.ControlParameterLogicFaceId.setLogicFaceId(1)
parameters.ControlParameterCost.setCost(1)
parameters.ControlParameterCapacity.setCapacity(1)
parameters.ControlParameterCount.setCount(1)
parameters.ControlParameterExpireTime.setExpireTime(1)
parameters.ControlParameterUri.setUri("/pku/sz")
parameters.ControlParameterLocalUri.setLocalUri("/local")
parameters.ControlParameterLogicFacePersistency.setPersistency(1)
parameters.ControlParameterUriScheme.setUriScheme(1)
parameters.ControlParameterMtu.setMtu(1)

let enc = new Encoder()
const suite1 = new benchmark.Suite()
suite1.add('wireEncode', ()=>{
    enc.encoderReset(MaxPacketSize, 0)
    parameters.wireEncode(enc)
}).on('cycle', (event) => {
    console.log(String(event.target))
}).on('complete', () =>{
    console.log('wireEncode finished')
}).run()

enc.encoderReset(MaxPacketSize, 0)
parameters.wireEncode(enc)
let buf = enc.getBuffer()
let parameters2 = new ControlParameters()
let block = createBlockByBuffer(buf, false)
const suite3 = new benchmark.Suite()
suite3.add('wireDecode', ()=>{
    parameters2.wireDecode(block)
}).on('cycle', (event) => {
    console.log(String(event.target))
}).on('complete', () =>{
    console.log('wireDecode finished')
}).run()